<cfcomponent extends="assets.calgrants.com.Base">

	<cfscript>
        import assets.calgrants.com.bo.OAPValue;
	</cfscript>
	
	<cffunction name="get" access="public" output="false" returntype="assets.calgrants.com.bo.OAPValue">
		<cfargument name="OAP_Value_ID" type="numeric" required="true" />
		<cfscript>
			if (arguments.OAP_Value_ID gt 0) {
				local.loadArgs = {};
				local.loadArgs.obj = new OAPValue();
				StructAppend(local.loadArgs, QueryToStruct(read(argumentCollection = arguments))[1]);
				return load(argumentCollection = local.loadArgs);
			} else {
				return new OAPValue();
			}
		</cfscript>
	</cffunction>
	
	<cffunction name="load" access="public" output="false" returntype="assets.calgrants.com.bo.OAPValue">
		<cfargument name="obj" type="assets.calgrants.com.bo.OAPValue" required="true" />
		<cfscript>
			local.obj = arguments.obj;
			if (IsDefined("arguments.OAP_Value_ID")) {
				local.obj.setOAP_Value_ID(arguments.OAP_Value_ID);
			}
			if (IsDefined("arguments.Deleted")) {
				local.obj.setDeleted(arguments.Deleted);
			}
			if (IsDefined("arguments.Active")) {
				local.obj.setActive(arguments.Active); 
			}
			if (IsDefined("arguments.Category")) {
				local.obj.setCategory(arguments.Category);
			}
			if (IsDefined("arguments.Subcategory")) {
				local.obj.setSubcategory(arguments.Subcategory);
			}
			if (IsDefined("arguments.Description")) {
				local.obj.setDescription(arguments.Description);
			}
			if (IsDefined("arguments.Sort_Order")) {
				local.obj.setSort_Order(arguments.Sort_Order);
			}
			if (IsDefined("arguments.Date_Created")) {
				local.obj.setDate_Created(arguments.Date_Created);
			}		
			return local.obj;
		</cfscript>
	</cffunction>

	<cffunction name="read" access="public" output="false" returntype="any">
		<cfargument name="OAP_Value_ID" required="false" default="" />
		<cfargument name="Deleted" required="false" default="0" />
		<cfargument name="Active" required="false" default="1" />
		<cfargument name="Category" required="false" default="" />
		<cfargument name="Subcategory" required="false" default="" />
		<cfargument name="Description" required="false" default="" />
		<cfargument name="Sort_Order" required="false" default="" />
		<cfargument name="Date_Created" required="false" default="" />
		<cfargument name="oapValueIDs" required="false" default="" />

		<cfset var recs = "">
		<cfstoredproc datasource="#getDatasource()#" procedure="readOAPValue">
			<cfprocparam value="#arguments.OAP_Value_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.OAP_Value_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Deleted#" cfsqltype="CF_SQL_BIT" null="#IIf(Len(Trim(arguments.Deleted)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Active#" cfsqltype="CF_SQL_BIT" null="#IIf(Len(Trim(arguments.Active)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Category#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Category)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Subcategory#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Subcategory)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Description#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Description)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Sort_Order#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Sort_Order)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Date_Created#" cfsqltype="CF_SQL_TIMESTAMP" null="#IIf(Len(Trim(arguments.Date_Created)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.oapValueIDs#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.oapValueIDs)) eq 0, true, false)#" />
			<cfprocresult name="recs" />
		</cfstoredproc>
		<cfreturn recs />
	</cffunction>

	<cffunction name="save" access="public" output="false" returntype="any">
		<cfargument name="oapValue" required="true" type="assets.calgrants.com.bo.OAPValue" />

		<cfstoredproc datasource="#getDatasource()#" procedure="saveOAPValue">
			<cfprocparam value="#oapValue.getOAP_Value_ID()#" cfsqltype="CF_SQL_INTEGER" variable="id" type="inout" null="false" />
			<cfprocparam value="#oapValue.getDeleted()#" cfsqltype="CF_SQL_BIT" null="false" />
			<cfprocparam value="#oapValue.getActive()#" cfsqltype="CF_SQL_BIT" null="false" />
			<cfprocparam value="#oapValue.getCategory()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#oapValue.getSubcategory()#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(oapValue.getSubcategory())) eq 0, true, false)#" />
			<cfprocparam value="#oapValue.getDescription()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#oapValue.getSort_Order()#" cfsqltype="CF_SQL_INTEGER" null="false" />
		</cfstoredproc>
		<cfreturn id />
	</cffunction>

	<cffunction name="destroy" access="public" output="false" returntype="any">
		<cfargument name="OAP_Value_ID" required="true" />

		<cfstoredproc datasource="#getDatasource()#" procedure="destroyOAPValue">
			<cfprocparam value="#arguments.OAP_Value_ID#" cfsqltype="CF_SQL_INTEGER" null="false" />
			<cfprocparam value="true" cfsqltype="CF_SQL_BIT" null="false" />
		</cfstoredproc>
		<cfreturn true />
	</cffunction>

</cfcomponent>

